package ge.telasi.tasks.ui.task;

import ge.telasi.tasks.model.TaskBody;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.Scrollable;

/**
 * @author dimitri
 */
public class TaskBodyList extends JPanel implements Scrollable {
    private static final long serialVersionUID = 3778075811528895437L;

    public void display(List<TaskBody> bodies) {
        removeAll();
        GridBagLayout layout = new GridBagLayout();
        setLayout(layout);
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = 0;
        c.weightx = 1;
        c.fill = GridBagConstraints.HORIZONTAL;
        for (TaskBody body : bodies) {
            TaskBodyPanel panel = new TaskBodyPanel(body);
            add(panel, c);
        }
        c.weighty = 1;
        add(new JPanel(), c);
    }

    public Dimension getPreferredScrollableViewportSize() {
        return getPreferredSize();
    }

    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
        return 10;
    }

    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
        return 100;
    }

    public boolean getScrollableTracksViewportWidth() {
        return true;
    }

    public boolean getScrollableTracksViewportHeight() {
        return false;
    }

}
